package com.tjetc._2string;

public class _7StringEffective {
    public static void main(String[] args) {

        long startTime;
        long endTime;
        // 测试StringBuffer的运行时间
        StringBuffer buffer = new StringBuffer("");
        // 当前时间的毫秒值
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 100000000; i++) {
            buffer.append(i);
        }
        endTime = System.currentTimeMillis();
        System.out.println("StringBuffer的执行时间：" + (endTime - startTime));

        // 测试StringBuilder的运行时间
        StringBuilder builder = new StringBuilder("");
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 100000000; i++) {
            builder.append(i);
        }
        endTime = System.currentTimeMillis();
        System.out.println("StringBuilder的执行时间：" + (endTime - startTime));

        // 测试String的运行时间
        String text = "";
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 300; i++) {
            text = text + i;
        }
        endTime = System.currentTimeMillis();
        System.out.println("String的执行时间：" + (endTime - startTime));

    }

}
